﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Sinchron
{
    public partial class ScreensaverForm : Form
    {
        private bool isMouseInitialised;
        private Point initialMousePosition;

        public ScreensaverForm()
        {
            InitializeComponent();
            Cursor.Hide();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
#if DEBUG
            TopMost = false;
#endif
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            GraphicsFunction.RenderSinchronBackground(ClientRectangle, e.Graphics);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            GraphicsFunction.RenderSinchron(ClientRectangle, e.Graphics);
        }

        private void ScreensaverForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseInitialised && initialMousePosition != e.Location)
            {
                HandleKeyOrMouseEvent();
            }
            else
            {
                isMouseInitialised = true;
                initialMousePosition = e.Location;
            }
        }

        private void ScreensaverForm_KeyOrMouseEvent(object sender, EventArgs e)
        {
            HandleKeyOrMouseEvent();
        }

        private void HandleKeyOrMouseEvent()
        {
            Cursor.Show();
            Application.Exit();
        }
    }
}
